﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace MatthiWare.PortChecker.UI
{
    public partial class DnsResolverDialong : Form
    {
        public DnsResolverDialong()
        {
            InitializeComponent();
        }

        private void btnResolver_Click(object sender, EventArgs e)
        {
            String webAddress = txtAddress.Text;
            webAddress = webAddress.Replace("https://", "");
            webAddress = webAddress.Replace("http://", "");
            webAddress = webAddress.Split(Char.Parse(@"/"))[0];
            txtAddress.Text = webAddress;

            try
            {
                txtIP.Text = Dns.GetHostEntry(webAddress).AddressList[0].ToString();

                txtIP.Focus();
                txtIP.SelectAll();
            }
            catch (Exception)
            {
                txtIP.Text = "Unable to resolve hostname";
            }


        }

        private void txtAddress_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btnResolver.PerformClick();
        }
    }
}
